<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
		<head>
				<base href="<%=basePath%>">
				<title>companyAdd.jsp</title>
				<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
				<meta http-equiv="description" content="this is my page">
				<meta http-equiv="content-type" content="text/html; charset=UTF-8">
				<link rel="stylesheet" href="plugins/bootstrap/css/bootstrap.min.css" type="text/css"></link>
				<link rel="stylesheet" href="plugins/FlatUI/dist/css/flat-ui.css" type="text/css"></link>
				<link rel="shortcut icon" href="plugins/FlatUI/dist/img/favicon.ico">
				<link rel="stylesheet" href="css/style.css">
				<link rel="stylesheet" href="plugins/bootstrap/css/bootstrap-fileupload.css" type="text/css"></link>
				<script type="text/javascript" src="js/jquery.js">
</script>
				<script src="plugins/bootstrap/js/bootstrap.min.js">
</script>
				<script type="text/javascript" src="plugins/FlatUI/dist/js/flat-ui.js">
</script>
				<script type="text/javascript" src="plugins/fwb/bootstrap-wysiwyg.js">
</script>
				<script src="plugins/fwb/external/jquery.hotkeys.js" type="text/javascript">
</script>
				<script type="text/javascript" src="js/productAdd.js">
</script>
				<script type="text/javascript" src="plugins/FlatUI/dist/js/application.js">
</script>
				<script type="text/javascript" src="plugins/bootstrap/js/bootstrap-fileupload.js">
</script>
				<script type="text/javascript">
$(function() {
	//拦截表单提交 
	$("form").submit(function() {

		if ($("#companyName").val() == "") {
			$("#companyNameResult").text("请填写公司名称！");
			$("#companyNameResult").attr("style", "color:red");
			return false;
		} else if ($("#financingInReturn").val() == "") {
			$("#financingInReturnResult").text("请填写佣金数！");
			$("#financingInReturnResult").attr("style", "color:red");
			return false;
		} else if ($("#content").text() == "") {
			$("#companyDetailResult").text("请填写企业简介！");
			return false;
		}
		$("#companyDetail").val($("#content").text());
		$("#companyDetailHtml").val($("#content").html());
	});

	//失去焦点操作
	$("#companyName").blur(function() {
		var companyName = $(this).val();
		if (companyName == "") {
			$("#companyNameResult").text("请输入公司名称");
			$("#companyNameResult").attr("style", "color:red");
			return;
		}
		$.ajax( {
			url : "ajaxCheckCompanyNameSame.action?companyName=" + companyName+"&companyID=0",
			type : "get",
			dateType : "text",
			success : function(result) {
				if (result == "error") {
					$("#companyNameResult").text("公司名已存在");
					$("#companyNameResult").attr("style", "color:red");
				} else {
					$("#companyNameResult").text("可用");
					$("#companyNameResult").attr("style", "color:green");
				}

			}

		})

	});
	$("#financingInReturn").blur(function() {
		var financingInReturn = $(this).val();
		if (financingInReturn == "") {
			$("#financingInReturnResult").text("请输入佣金数");
			$("#financingInReturnResult").attr("style", "color:red");
			return;
		}
		if (isNaN(financingInReturn)) {
			$("#financingInReturnResult").text("佣金数为数字");
			$("#financingInReturnResult").attr("style", "color:red");
			return;
		}
		if (financingInReturn < 0) {
			$("#financingInReturnResult").text("佣金数正数");
			$("#financingInReturnResult").attr("style", "color:red");
			return;
		}
		$("#financingInReturnResult").text("");
	});
	$("#content").blur(function() {
		var companyDetail = $(this).text();
		if (companyDetail == "") {
			$("#companyDetailResult").text("请输入公司介绍");
			return;
		}
		$("#companyDetailResult").text("");

	});
})
</script>
		</head>
		<body style="padding: 5px 10px">
				<div class="panel panel-primary">
						<div class="panel-heading">
								<h3 class="panel-title">
										企业添加
								</h3>
						</div>
						<div class="panel-body">
								<form class="form-horizontal" role="form" action="addCompany.action" method="post" enctype="multipart/form-data">
										<div class="form-group">
												<label for="companyName" class="col-lg-2 control-label">
														企业名称
												</label>
												<div class="col-lg-10">
														<input type="text" name="companyName" class="form-control" id="companyName" placeholder="产品名称" value="${company.companyName}">
														<span id="companyNameResult">${errorMap.companyName}</span>
												</div>
										</div>
										<div class="form-group">
												<label for="productRate" class="col-lg-2 control-label">
														融资佣金
												</label>
												<div class="col-lg-10">
														<div class="input-group col-lg-3" style="float: left;">
																<input type="text" id="financingInReturn" name="financingInReturn" value="${company.financingInReturn}" class="form-control" placeholder="佣金数">
																<span class="input-group-addon">%</span>
														</div>
														<span id="financingInReturnResult">${errorMap.financingInReturn}</span>
												</div>
										</div>
										<div class="form-group">
												<label class="col-lg-2 control-label">
														缩略图
												</label>
												<div class="col-lg-10">
														<div class="fileupload fileupload-new" data-provides="fileupload">
																<div class="input-group">
																		<div class="fileupload-new thumbnail" style="width: 130px; height: 139px;">
																				<img src="images/nopic.gif" alt="" />
																		</div>
																		<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;">
																		</div>
																		<div>
																				<span class="btn btn-default btn-file"> <span class="fileupload-new"> <i class="fa fa-paper-clip"></i> 选择文件 </span> <span class="fileupload-exists"> <i
																								class="fa fa-undo"></i> 替换 </span> <input name="imagefile" type="file" class="default" /> </span>
																				<a href="#" class="btn btn-danger fileupload-exists" data-dismiss="fileupload"> <i class="fa fa-trash-o"></i> 移除 </a>
																		</div>
																</div>
														</div>
												</div>
										</div>
										<div class="form-group">
												<label for="content" class="col-lg-2 control-label">
														内容
												</label>
												<div class="col-lg-10">
														<!-- 			asdjalkj dlkajsdkl asjdlkaj sdkl asd -->
														<div class="btn-toolbar" data-role="editor-toolbar" data-target="#content">
																<div class="btn-group">
																		<a class="btn" data-edit="indent" title="Indent (Tab)"> Tab缩进 </a>
																</div>
																<div class="btn-group">
																		<a class="btn" data-edit="justifyleft" title="Align Left (Ctrl/Cmd+L)"> 左对齐 </a>
																		<a class="btn" data-edit="justifycenter" title="Center (Ctrl/Cmd+E)"> 居中­ </a>
																		<a class="btn" data-edit="justifyright" title="Align Right (Ctrl/Cmd+R)"> 右对齐 </a>
																		<a class="btn" data-edit="justifyfull" title="Justify (Ctrl/Cmd+J)"> 自动调整 </a>
																</div>
																<div class="btn-group">
																		<a class="btn" data-edit="undo" title="Undo (Ctrl/Cmd+Z)"> 撤销 </a>
																		<a class="btn" data-edit="redo" title="Redo (Ctrl/Cmd+Y)"> 恢复 </a>
																</div>
														</div>
														<!--               	此处不能换行 -->
														<div id="content" style="overflow: scroll; max-height: 300px; border: 1px solid; height: 200px;">${company.companyDetail}</div>
												</div>
												<span id="companyDetailResult" style="color: red">${errorMap.companyDetail}</span>
										</div>
										<!-- 隐藏域 -->
										<input type="hidden" id="companyDetail" name="companyDetail">
										<input id="companyDetailHtml" type="hidden" name="companyDetailHtml">
										<div class="form-group">
												<div class="col-lg-offset-2 col-lg-10">
														<button type="submit" class="btn btn-lg btn-success" style="padding: 15px 60px; border-radius: 0px;">
																添加
														</button>
												</div>
										</div>
								</form>
						</div>
				</div>
		</body>
</html>
